package io.github.bffcorreia.fole;

import android.widget.TextView;

class MaxCharsStateHandler
        implements TextViewStateHandler
{
    private final TextView textView;
    private final String ellipsisPlaceholder;
    private final int maxChars;

    MaxCharsStateHandler(TextView textView, String ellipsisPlaceholder, int maxChars)
    {
        this.textView = textView;
        this.ellipsisPlaceholder = ellipsisPlaceholder;
        this.maxChars = maxChars;
    }

    public boolean isTextExpanded()
    {
        return this.textView.length() - this.ellipsisPlaceholder.length() > this.maxChars;
    }

    public String ellipsizedText()
    {
        return this.textView.getText().subSequence(0, this.maxChars) + this.ellipsisPlaceholder;
    }
}
